package com.file_.transformation;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/*
 * 使用InputStreamReader 转换流解决中文乱码问题
 * 功能：将字节流FileInputStream转换成 字符流InputStreamReader，指定编码为utf-16
 * */
public class Demo2 {
    public static void main(String[] args) throws IOException {
        String filePath = "D:\\A_Test\\a_utf16LE.txt";
        // 1、通过转换流，把FileInputStream字节流转成InputStreamReader字符流，指定其编码为utf-16
        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(filePath), "utf-16");
        // 2、把inputStreamReader传入BufferedReader，以便读取
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

//        // 可以将1和2合在一起
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "utf-16"));
        System.out.println(bufferedReader.readLine());
        // 3、关闭外层流
        bufferedReader.close();

    }
}
